package com.ymatou.iapi.godmch.testcase;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONException;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.godmch.parameter.adminBindAgentBean;
import com.ymatou.iapi.godmch.parameter.applyAgentBean;
import com.ymatou.iapi.godmch.parameter.approveAgentBean;
import com.ymatou.iapi.godmch.parameter.createIndepMchBean;
import com.ymatou.iapi.godmch.parameter.createagentBean;
import com.ymatou.iapi.godmch.parameter.reApplyAgentBean;
import com.ymatou.iapi.godmch.parameter.rejectAgentBean;
import com.ymatou.iapi.godmch.service.adminBindAgentCall;
import com.ymatou.iapi.godmch.service.applyAgentCall;
import com.ymatou.iapi.godmch.service.createIndepMchCall;
import com.ymatou.iapi.godmch.service.createagentCall;
import com.ymatou.iapi.godmch.service.rejectAgentCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.mch_info;
import com.ymttest.database.model.mch_relation;
import com.ymttest.database.sqlwapper.godmch.agent_typeWapper;
import com.ymttest.database.sqlwapper.godmch.country_infoWapper;
import com.ymttest.database.sqlwapper.godmch.mch_infoWapper;
import com.ymttest.database.sqlwapper.godmch.mch_relationWapper;
import com.ymttest.utils.TestDataManager;
/**
*代理审核拒绝
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_rejectAgent{
	private static rejectAgentBean bean;
	private static rejectAgentCall call;
	
    agent_typeWapper agentTypeWapper=new agent_typeWapper();
	mch_infoWapper infoWapper=new mch_infoWapper();
	country_infoWapper country_infoWapper=new country_infoWapper();
	mch_relationWapper relationWapper=new mch_relationWapper();
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("代理审核拒绝");
	}

	@Before
	public void caseUp() {
		bean=new rejectAgentBean();
		call=new rejectAgentCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	private void  check_verify(applyAgentBean applyBean,applyAgentCall applyCall) throws InterruptedException, JSONException {
		
		Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
		
		//mch_relation
		mch_relation relation=relationWapper.selectByPrimaryKey(applyCall.getAgentId(), applyBean.getMchId()).get(0);
		Logger.verifyEquals(-3, relation.getAgentType(), "验证AgentType");
		Logger.verifyEquals(-3, relation.getAgentModel(), "验证AgentModel");
		Logger.verifyEquals(-3, relation.getState(), "验证state");
		//mch_info
		List<Integer> mchIds=new ArrayList<Integer>();
		mchIds.add(applyCall.getAgentId());
		mch_info  info=infoWapper.selectbyMchIds(mchIds).get(0);
		Logger.verifyEquals(-3, info.getState(), "验证state");
		
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_rejectAgent_001() {
		Logger.start(true,"正例-代理审核拒绝-默认");
		try {
			applyAgentBean applyBean=GodmchManageCallService.InitApplyAgentBean();
			applyAgentCall applyCall=GodmchManageCallService.ApplyAgentCall(applyBean);
			
			bean.setMchId(applyBean.getMchId());
			bean.setAgentId(applyCall.getAgentId());
			bean.setReason("代理审核拒绝_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();			
			
			check_verify(applyBean,applyCall);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_rejectAgent_004() {
		Logger.start(true,"正例-代理审核拒绝-mchId不存在");
		try {
			applyAgentBean applyBean=GodmchManageCallService.InitApplyAgentBean();
			applyAgentCall applyCall=GodmchManageCallService.ApplyAgentCall(applyBean);
			
			bean.setMchId(9999);
			bean.setAgentId(applyCall.getAgentId());
			bean.setReason("代理审核拒绝_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("5017", call.getStatusCode1(), "验证status");
			Logger.verifyEquals(true, call.getMessage().contains("上级商户不存在"), "验证msg");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_rejectAgent_005() {
		Logger.start(true,"正例-代理审核拒绝-mchId为空");
		try {
			
			applyAgentBean applyBean=GodmchManageCallService.InitApplyAgentBean();
			applyAgentCall applyCall=GodmchManageCallService.ApplyAgentCall(applyBean);
			
			bean.setMchId(null);
			bean.setAgentId(applyCall.getAgentId());
			bean.setReason("代理审核拒绝_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();				
			
			Logger.verifyEquals("4001", call.getStatusCode1(), "验证status");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_rejectAgent_006() {
		Logger.start(true,"正例-代理审核拒绝-agentId代理商id不存在");
		try {
			applyAgentBean applyBean=GodmchManageCallService.InitApplyAgentBean();
			applyAgentCall applyCall=GodmchManageCallService.ApplyAgentCall(applyBean);
			
			bean.setMchId(applyBean.getMchId());
			bean.setAgentId(99999);
			bean.setReason("代理审核拒绝_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();				
			
			Logger.verifyEquals("5002", call.getStatusCode1(), "验证status");
			Logger.verifyEquals(true, call.getMessage().contains("代理商不存在"), "验证msg");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_rejectAgent_007() {
		Logger.start(true,"正例-代理审核拒绝-agentId代理商id为空");
		try {
			
			applyAgentBean applyBean=GodmchManageCallService.InitApplyAgentBean();
			applyAgentCall applyCall=GodmchManageCallService.ApplyAgentCall(applyBean);
			
			bean.setMchId(applyBean.getMchId());
			bean.setAgentId(99999);
			bean.setReason("代理审核拒绝_"+TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();				
			
			Logger.verifyEquals("5002", call.getStatusCode1(), "验证status");
			Logger.verifyEquals(true, call.getMessage().contains("代理商不存在"), "验证msg");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_rejectAgent_008() {
		Logger.start(true,"正例-代理审核拒绝-拒绝理由为空");
		try {
			
			applyAgentBean applyBean=GodmchManageCallService.InitApplyAgentBean();
			applyAgentCall applyCall=GodmchManageCallService.ApplyAgentCall(applyBean);
			
			bean.setMchId(applyBean.getMchId());
			bean.setAgentId(applyCall.getAgentId());
			bean.setReason(null);
			call.setData(bean);
			call.callService();				
			
			check_verify(applyBean,applyCall);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_rejectAgent_009() {
		Logger.start(true,"正例-独立云版本代理审核拒绝");
		try {
			
			createIndepMchBean createBean=GodmchManageCallService.InitCreateIndepMchBean();
			createIndepMchCall createCall=GodmchManageCallService.CreateIndepMchCall(createBean);
			//代理商户
			createIndepMchBean createBean2=GodmchManageCallService.InitCreateIndepMchBean();
			createIndepMchCall createCall2=GodmchManageCallService.CreateIndepMchCall(createBean2);
			//运营绑定的代理
			adminBindAgentBean adminBindAgentBean=GodmchManageCallService.initAdminBindAgent(createCall.getmchId(),createCall2.getmchId());
			adminBindAgentCall adminBindAgentCall=GodmchManageCallService.AdminBindAgent(adminBindAgentBean);
	
			
			bean.setMchId(createCall.getmchId());
			bean.setAgentId(createCall2.getmchId());
			bean.setReason(null);
			call.setData(bean);
			call.callService();				
			
			//check_verify(applyBean,applyCall);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_rejectAgent_010() {
		Logger.start(true,"正例-独立云版本代理审核拒绝-删除-重新申请-再拒绝");
		try {
			
			createIndepMchBean createBean=GodmchManageCallService.InitCreateIndepMchBean();
			createIndepMchCall createCall=GodmchManageCallService.CreateIndepMchCall(createBean);
			//代理商户
			createIndepMchBean createBean2=GodmchManageCallService.InitCreateIndepMchBean();
			createIndepMchCall createCall2=GodmchManageCallService.CreateIndepMchCall(createBean2);
			//运营绑定的代理
			adminBindAgentBean adminBindAgentBean=GodmchManageCallService.initAdminBindAgent(createCall.getmchId(),createCall2.getmchId());
			adminBindAgentCall adminBindAgentCall=GodmchManageCallService.AdminBindAgent(adminBindAgentBean);
	
			//审核通过
			approveAgentBean approveAgentBean=GodmchManageCallService.approveAgentBeanV2(createCall.getmchId(),createCall2.getmchId());
			GodmchManageCallService.ApproveAgentCall(approveAgentBean);
			
//			bean.setMchId(createCall.getmchId());
//			bean.setAgentId(createCall2.getmchId());
//			bean.setReason(null);
//			call.setData(bean);
//			call.callService();				
			//解绑
			GodmchManageCallService.InitremovemchForAgent(createCall.getmchId(),createCall2.getmchId());
			//重新
			reApplyAgentBean reApplyAgentBean=GodmchManageCallService.initReApplyAgentBean(createCall.getmchId(),createCall2.getmchId());
			GodmchManageCallService.reApplyAgentCall(reApplyAgentBean);
			
			
			bean.setMchId(createCall.getmchId());
			bean.setAgentId(createCall2.getmchId());
			bean.setReason(null);
			call.setData(bean);
			call.callService();		
			
			//check_verify(applyBean,applyCall);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_rejectAgent_011() {
		Logger.start(true,"正例-独立云版本代理审核拒绝-重新申请-再拒绝");
		try {
			
			createIndepMchBean createBean=GodmchManageCallService.InitCreateIndepMchBean();
			createIndepMchCall createCall=GodmchManageCallService.CreateIndepMchCall(createBean);
			//代理商户
			createIndepMchBean createBean2=GodmchManageCallService.InitCreateIndepMchBean();
			createIndepMchCall createCall2=GodmchManageCallService.CreateIndepMchCall(createBean2);
			//运营绑定的代理
			adminBindAgentBean adminBindAgentBean=GodmchManageCallService.initAdminBindAgent(createCall.getmchId(),createCall2.getmchId());
			adminBindAgentCall adminBindAgentCall=GodmchManageCallService.AdminBindAgent(adminBindAgentBean);
	
//			//审核通过
//			approveAgentBean approveAgentBean=GodmchManageCallService.approveAgentBeanV2(createCall.getmchId(),createCall2.getmchId());
//			GodmchManageCallService.ApproveAgentCall(approveAgentBean);
			
			bean.setMchId(createCall.getmchId());
			bean.setAgentId(createCall2.getmchId());
			bean.setReason(null);
			call.setData(bean);
			call.callService();				
			//解绑
		//	GodmchManageCallService.InitremovemchForAgent(createCall.getmchId(),createCall2.getmchId());
			//重新
			reApplyAgentBean reApplyAgentBean=GodmchManageCallService.initReApplyAgentBean(createCall.getmchId(),createCall2.getmchId());
			GodmchManageCallService.reApplyAgentCall(reApplyAgentBean);
			
			
			bean.setMchId(createCall.getmchId());
			bean.setAgentId(createCall2.getmchId());
			bean.setReason(null);
			call.setData(bean);
			call.callService();		
			
			//check_verify(applyBean,applyCall);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}